#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int calculate(string s) {
        vector<int> ans;
        int i = 0, n = s.size();
        char op = '+';
        while (i < n)
        {
            while (s[i] == ' ') i++;
            if (s[i] >= '0' && s[i] <= '9')
            {
                int temp = 0;
                while (i < n && s[i] >= '0' && s[i] <= '9')
                    temp = temp * 10 + (s[i++] - '0');
                if (op == '+') ans.push_back(temp);
                else if (op == '-') ans.push_back(-temp);
                else if (op == '*') ans.back() *= temp;
                else ans.back() /= temp;
            }
            else
            {
                op = s[i];
                i++;
            }
        }


        int ret = 0;
        for (int num : ans)
        {
            ret += num;
        }
        return ret;
    }
};